package com.snack.util;

import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Set;

/**
 * 将Date数据或14位的字符串转换成正常的日期形式
 * 如:20061120152314 -&gt; 2006-11-20 15:23:14
 * @author: Dishine
 * Date: 2006-12-21
 * Time: 16:51:29
 * 1.修改人:jinlei; MAIL:jinlei@c-platform.com; 修改时间:2007-4-23; 修改原因:get方法中如果key最后6位都是0，则转化之后的结果将后六位全部去掉
 */
public class TimeMap implements Map  {
    public Object get(Object key) {
        if (key == null) return null;

        if (key instanceof Date) {
            Date d = (Date) key;
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            return sdf.format(d);
        }
        else {
            String s = key.toString();
            s = s.replaceAll("000000", "");
            switch(s.length()) {
                case 8:
                    return s.substring(0, 4) + "-" +
                            s.substring(4, 6) + "-" +
                            s.substring(6, 8);
                case 12:
                    return s.subSequence(0, 4) + "-" +
                            s.substring(4, 6) + "-" +
                            s.substring(6, 8) + " " +
                            s.substring(8, 10) + ":" +
                            s.substring(10, 12);
                case 14:
                    return s.substring(0, 4) + "-" +
                            s.substring(4, 6) + "-" +
                            s.substring(6, 8) + " " +
                            s.substring(8, 10) + ":" +
                            s.substring(10, 12) + ":" +
                            s.substring(12);
                default:
                    return key;
            }
        }
    }

    public int size() {
        return 0;
    }

    public boolean isEmpty() {
        return false;
    }

    public boolean containsKey(Object key) {
        return false;
    }

    public boolean containsValue(Object value) {
        return false;
    }

    public Object put(Object key, Object value) {
        return null;
    }

    public Object remove(Object key) {
        return null;
    }

    public void putAll(Map t) {
    }

    public void clear() {
    }

    public Set keySet() {
        return null;
    }

    public Collection values() {
        return null;
    }

    public Set entrySet() {
        return null;
    }
}
